class HomeController < ApplicationController
  
  before_filter :check_account, :set_default_page_for_user
  
  def index
    @companies = Company.all
  end
  
  # Render about page
  def about
  end
  
  private
  
  # Ensures that the account exists and renders a login page
  def check_account
    if current_subdomain
      redirect_to unauthorized_path(:subdomain => current_subdomain) unless current_account
      redirect_to login_path if !logged_in? && current_account
    end
  end
  
  # Redirect logged in user to the profile page
  def set_default_page_for_user
    redirect_to user_path(current_user.id, :subdomain => current_user.company.subdomain) if logged_in?
  end
end
